package aryn.framework.display.drawable;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;

import aryn.framework.display.MyCanvas;
import aryn.framework.utilities.Util;

public class DrawingString extends Drawable {
	private String string;
	private Color color;
	
	public DrawingString(String string, int x, int y, Priority priority, Color color, MyCanvas canvas) {
		super(x, y, priority, canvas);
		this.string = string;
		this.color = color;
	}
	
	public DrawingString(String string, int x, int y, MyCanvas canvas) {
		this(string, x, y, Priority.FOREGROUND, Color.BLACK, canvas);
	}
	
	@Override
	public void draw(Graphics g) {
		Color prec = g.getColor();
		g.setColor(this.color);
		g.drawString(string, x, y);
		g.setColor(prec);
	}

	@Override
	public boolean isMouseOver(int mouseX, int mouseY) {
		Font font = canvas.getFont();
		FontMetrics metrics = canvas.getFontMetrics(font);
        Rectangle2D bounds = metrics.getStringBounds(string, null);
        int x = this.x;
        int y = this.y - metrics.getHeight();
        return Util.mouseBound(mouseX, mouseY, x, y, x + (int)bounds.getWidth(), y + (int)bounds.getHeight());
	}	
	
	  // ******************* \\
	 //   GETTERS & SETTERS	  \\
	// *********************** \\
	
	public String getString() {
		return string;
	}
	public void setString(String string) {
		this.string = string;
	}

}
